import { getToken, setToken, removeToken } from '@/utils/auth'
import routers from "@/utils/constRouter";

const user = {
  state: {
    user: null,
    token: getToken()
  },

  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_USER: (state,user) => {
      state.user = user;
    }
  },

  actions:{
     // 获取用户信息
     GetUserInfo({ commit, state }) {
      return new Promise((resolve, reject) => {
          commit("SET_USER",{role:"管理员",userName:"张兆光",avatar:'http://img4.duitang.com/uploads/item/201611/03/20161103153308_YzicQ.jpeg'})
          resolve(routers)
        }).catch(error => {
          reject(error)
        })
    },
    //退出登录
    Logout({commit}){
      removeToken()
    }
  }
}



export default user
